﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess
{
    public class StudentDaO
    {
        ConnectionDatabase conn;
        SqlDataReader dr;
        SqlCommand cmd;
        public StudentDaO()
        {
            conn = new ConnectionDatabase();
        }
        // kiểm tra đăng nhập của sinh viên 
        public string LoginStudent(string UserName, string PassWord)
        {
            string Name;
            SqlConnection con = conn.GetConnection();
            try
            {
                con.Open();
                cmd = new SqlCommand("SP_LoginStudent", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = UserName;
                cmd.Parameters.Add("@PassWord", SqlDbType.VarChar).Value = PassWord;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    Name = dr.GetString(2);
                    return Name;
                }
                else
                {
                    Name = null;
                    return Name;
                }
            }
            catch (Exception e) { throw; }
            finally { con.Close(); }
        }
        public int SP_CodeProfileStudent(string UserName)
        {
            int code = 0;
            SqlConnection con = conn.GetConnection();
            try
            {
                con.Open();
                cmd = new SqlCommand("SP_CodeProfileStudent", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = UserName;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    code = dr.GetInt32(0);
                    return code;
                }
                else
                {
                    return code;
                }
            }
            catch (Exception e) { throw; }
            finally { con.Close(); }
        }
    }
}
